package smedi.ismedi.web.bff.controller.authortiy;

import com.smedi.ismedi.authoritymanagement.api.dto.request.MultiRoleOnePersonRequest;
import com.smedi.ismedi.authoritymanagement.api.dto.request.OneRoleMultiPersonRequest;
import com.smedi.ismedi.authoritymanagement.api.dto.request.RoleBasicRequest;
import com.smedi.ismedi.authoritymanagement.api.dto.request.RolePermissionDetailGroupRequest;
import com.smedi.ismedi.authoritymanagement.api.dto.response.RoleBasicResponse;
import com.smedi.ismedi.authoritymanagement.api.dto.response.RoleMemberResponse;
import com.smedi.ismedi.authoritymanagement.api.feign.RemoteAuthorityRoleManagementFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-7-4 15:45
 */
@Slf4j
@RestController
@Api(tags = {"权限管理角色配置接口"})
@RequestMapping("/webbff/v1/authority/roleManagement")
@AllArgsConstructor
public class AuthorityRoleManagementController {
    private final RemoteAuthorityRoleManagementFeignApi remoteAuthorityRoleManagementFeignApi;

    /**
     * 保存角色信息
     *
     * @param roleBasicRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "保存角色信息")
    @PostMapping(value = "/saveRoleBasic")
    public ResponseData<RoleBasicResponse> postSaveRoleBasic(@Validated @RequestBody RoleBasicRequest roleBasicRequest) {
        return remoteAuthorityRoleManagementFeignApi.postSaveRoleBasic(roleBasicRequest);
    }

    /**
     * 批量保存角色信息
     *
     * @param roleBasicRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "批量保存角色信息")
    @PostMapping(value = "/batchSaveRoleBasic")
    public ResponseData<List<RoleBasicResponse>> postBatchSaveRoleBasic(@Validated @RequestBody List<RoleBasicRequest> roleBasicRequest) {
        return remoteAuthorityRoleManagementFeignApi.postBatchSaveRoleBasic(roleBasicRequest);
    }

    /**
     * 删除角色信息
     *
     * @param roleId
     * @return
     */
    @ApiOperation(httpMethod = "DELETE", value = "删除角色信息")
    @DeleteMapping(value = "/deleteRoleBasic")
    public ResponseData<Boolean> deleteRoleBasic(@RequestParam("roleId") Long roleId) {
        return remoteAuthorityRoleManagementFeignApi.deleteRoleBasic(roleId);
    }

    /**
     * 批量删除角色信息
     *
     * @param roleIds
     * @return
     */
    @ApiOperation(httpMethod = "DELETE", value = "批量删除角色信息")
    @DeleteMapping(value = "/batchDeleteRoleBasics")
    public ResponseData<Boolean> deleteBatchDeleteRoleBasics(@RequestParam("roleIds") List<Long> roleIds) {
        return remoteAuthorityRoleManagementFeignApi.deleteBatchDeleteRoleBasics(roleIds);
    }

    /**
     * 角色设置界面查询分页
     *
     * @param offset
     * @param pageSize
     * @param roleName
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "角色设置界面查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "offset", value = "页码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "roleName", value = "角色名称", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping(value = "/queryRoleBasicPagination")
    public ResponseData<PaginationData<RoleBasicResponse>> getQueryRoleBasicPagination(@RequestParam("offset") Long offset,
                                                                                       @RequestParam("pageSize") Long pageSize,
                                                                                       @RequestParam(value = "roleName", required = false) String roleName,
                                                                                       @RequestParam(value = "roleType", required = false) String roleType) {
        return remoteAuthorityRoleManagementFeignApi.getQueryRoleBasicPagination(offset, pageSize, roleName, roleType);
    }

    /**
     * 根据人员id获取所有角色123
     *
     * @param personId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "根据人员id获取所有角色")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "personId", value = "人员id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/getQueryRolesByPersonId")
    public ResponseData<List<RoleBasicResponse>> getQueryRolesByPersonId(@RequestParam("personId") Long personId) {
        return remoteAuthorityRoleManagementFeignApi.getQueryRolesByPersonId(personId);
    }

    /**
     * 批量保存角色分配
     *
     * @param oneRoleMultiPersonRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "批量保存角色分配")
    @PostMapping(value = "/postBatchSaveOneRoleForMultiPerson")
    public ResponseData<Boolean> postBatchSaveOneRoleForMultiPerson(@RequestBody OneRoleMultiPersonRequest oneRoleMultiPersonRequest) {
        return remoteAuthorityRoleManagementFeignApi.postBatchSaveOneRoleForMultiPerson(oneRoleMultiPersonRequest);
    }

    /**
     * 为一个人添加多个角色信息9
     *
     * @param multiRoleOnePersonRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "为一个人添加多个角色信息")
    @PostMapping(value = "/postBatchSaveMultiRoleForOnePerson")
    public ResponseData<Boolean> postBatchSaveMultiRoleForOnePerson(@RequestBody MultiRoleOnePersonRequest multiRoleOnePersonRequest) {
        return remoteAuthorityRoleManagementFeignApi.postBatchSaveMultiRoleForOnePerson(multiRoleOnePersonRequest);
    }

    /**
     * 删除角色成员信息
     *
     * @param roleMemberId
     * @return
     */
    @ApiOperation(httpMethod = "DELETE", value = "删除角色成员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "roleMemberId", value = "角色分配id", dataType = "Long", dataTypeClass = Long.class)
    })
    @DeleteMapping(value = "/deleteRoleMember")
    public ResponseData<Boolean> deleteRoleMember(@RequestParam("roleMemberId") Long roleMemberId) {
        return remoteAuthorityRoleManagementFeignApi.deleteRoleMember(roleMemberId);
    }

    /**
     * 角色分配界面查询分页
     *
     * @param offset
     * @param pageSize
     * @param lastName
     * @param userName
     * @param mobile
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "角色分配界面查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "offset", value = "页码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "roleId", value = "角色id", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "lastName", value = "姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "query", name = "userName", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "query", name = "mobile", value = "手机号", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping(value = "/queryRoleMemberPagination")
    public ResponseData<PaginationData<RoleMemberResponse>> getQueryRoleMemberPagination(@RequestParam("offset") Long offset,
                                                                                         @RequestParam("pageSize") Long pageSize,
                                                                                         @RequestParam(value = "roleId") Long roleId,
                                                                                         @RequestParam(value = "lastName", required = false) String lastName,
                                                                                         @RequestParam(value = "userName", required = false) String userName,
                                                                                         @RequestParam(value = "mobile", required = false) String mobile) {
        return remoteAuthorityRoleManagementFeignApi.getQueryRoleMemberPagination(offset, pageSize, roleId, lastName, userName, mobile);
    }

    /**
     * 批量保存角色功能组结构id
     *
     * @param rolePermissionDetailGroupRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "批量保存角色功能组结构id")
    @PostMapping(value = "/batchSaveRolePermissionDetails")
    public ResponseData<Boolean> postBatchSaveRolePermissionDetails(@Validated @RequestBody RolePermissionDetailGroupRequest rolePermissionDetailGroupRequest) {
        return remoteAuthorityRoleManagementFeignApi.postBatchSaveRolePermissionDetails(rolePermissionDetailGroupRequest);
    }

    /**
     * 传入角色名称与角色名称一致的角色
     *
     * @param roleName
     * @param fuzzy
     * @param showPersonId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "传入角色名称与角色名称一致的角色")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "roleName", value = "角色名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "query", name = "fuzzy", value = "模糊匹配", dataType = "boolean", dataTypeClass = boolean.class),
            @ApiImplicitParam(paramType = "query", name = "showPersonId", value = "显示人员id", dataType = "boolean", dataTypeClass = boolean.class)
    })
    @GetMapping(value = "/queryRoleByRoleName")
    public ResponseData<List<RoleBasicResponse>> getQueryAllPersonIdsByRoleId(@RequestParam("roleName") String roleName,
                                                                              @RequestParam("fuzzy") boolean fuzzy,
                                                                              @RequestParam("showPersonId") boolean showPersonId) {
        return remoteAuthorityRoleManagementFeignApi.getQueryAllPersonIdsByRoleId(roleName, fuzzy, showPersonId);
    }
}
